package com.gedi.data.InputFormate.CombineInputFormate;

import com.gedi.data.bigter.preduce.MyPreduce;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.CombineTextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.IOException;

/**
 * @Author:RenPu
 * @Date: 2020/1/2 18:43
 * @Version: 1.0
 * @description:
 */
public class WordConfigApplication {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        //1:创建mapreduce任务对象

        Configuration conf = new Configuration();
        String jobName="wordName";
        Job job = Job.getInstance(conf, jobName);
        job.setJarByClass(WordConfigApplication.class);

        //2：设置计算数据的输入格式以及输出格式（文本）
        job.setInputFormatClass(CombineTextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        //3：指定数据来源的位置以及结果输出的位置
        //本地数据读取，以及输出位置也在本地，路径需加 file:///
        CombineTextInputFormat.addInputPath(job,new Path("file:///d:\\CombineText"));
        //输出的目录必须不存在
        TextOutputFormat.setOutputPath(job,new Path("file:///d:\\result3"));

        //4：指定mapreduce的mapper阶段和preduce阶段
        job.setMapperClass(MyMapper.class);
        job.setReducerClass(MyPreduce.class);

        //优化策略：combine合并操作；
        job.setCombinerClass(MyPreduce.class);

        //5:设置mapper和reduce阶段keyout和valueout的类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        //6：任务提交
        job.waitForCompletion(true);//输出打印日志



    }
}
